#include<iostream>
#include<vector>

std::vector<int> productExceptSelf(std::vector<int>& nums) {
    int n = nums.size();
    std::vector<int> answer;
    std::vector<int> front(n, 1);
    std::vector<int> back(n, 1);

    for (int i = 1; i < n; i++)
    {
        front[i] = front[i - 1] * nums[i - 1];
    }
    for (int i = n - 2; i >= 0; i--)
    {
        back[i] = back[i + 1] * nums[i + 1];
    }
    for (int i = 0; i < n; i++)
    {
        int tmp = front[i] * back[i];
        answer.push_back(tmp);
    }
    return answer;
}